﻿@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@{
    var userConfig = config.GetUserConfig(User);
    var userLanguage = userConfig.UserLanguage;
    var hideZero = userConfig.HideZero;
}
@model CostTableForVehicle
@if (Model.CollisionRecordSum + Model.ServiceRecordSum + Model.GasRecordSum + Model.TaxRecordSum + Model.UpgradeRecordSum > 0)
{
    <div>
        <div class="modal-header">
            <h5 class="modal-title">@(translator.Translate(userLanguage, "Vehicle Cost Breakdown"))</h5>
            <button type="button" class="btn-close" onclick="hideDataTable()" aria-label="Close"></button>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-12">
                    <table class="table table-hover">
                        <thead class="sticky-top">
                            <tr class="d-flex">
                                <th scope="col" class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Type")</th>
                                <th scope="col" style="cursor:pointer;" onclick="toggleCostTableHint()" class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Cost Per Day")<span class="cost-table-hint d-none">@($"({Model.NumberOfDays.ToString("N0")})")</span></th>
                                <th scope="col" style="cursor:pointer;" onclick="toggleCostTableHint()" class="col-3 flex-grow-1">@translator.Translate(userLanguage, Model.DistanceUnit)<span class="cost-table-hint d-none">@($"({Model.TotalDistance.ToString("N0")})")</span></th>
                                <th scope="col" class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Total")</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="d-flex">
                                <td class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Service Records")</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.ServiceRecordPerDay.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.ServiceRecordPerMile.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.ServiceRecordSum.ToString("C2"), hideZero))</td>
                            </tr>
                            <tr class="d-flex">
                                <td class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Repairs")</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.CollisionRecordPerDay.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.CollisionRecordPerMile.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.CollisionRecordSum.ToString("C2"), hideZero))</td>
                            </tr>
                            <tr class="d-flex">
                                <td class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Upgrades")</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.UpgradeRecordPerDay.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.UpgradeRecordPerMile.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.UpgradeRecordSum.ToString("C2"), hideZero))</td>
                            </tr>
                            <tr class="d-flex">
                                <td class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Fuel")</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.GasRecordPerDay.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.GasRecordPerMile.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.GasRecordSum.ToString("C2"), hideZero))</td>
                            </tr>
                            <tr class="d-flex">
                                <td class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Taxes")</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.TaxRecordPerDay.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.TaxRecordPerMile.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.TaxRecordSum.ToString("C2"), hideZero))</td>
                            </tr>
                        </tbody>
                        <tfoot>
                            <tr class="d-flex fw-bold">
                                <td class="col-3 flex-grow-1">@translator.Translate(userLanguage, "Total")</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.TotalPerDay.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.TotalPerMile.ToString("C2"), hideZero))</td>
                                <td class="col-3 flex-grow-1">@(StaticHelper.HideZeroCost(Model.TotalCost.ToString("C2"), hideZero))</td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
}
else
{
    <div class="text-center">
        <h4>@translator.Translate(userLanguage, "No data found or all records have zero sums, insert records with non-zero sums to see visualizations here.")</h4>
    </div>
}
